package com.gk.panda.apis.task;

import com.gk.panda.apis.dahua.service.SCADADemoHD;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Description 大华设备数据获取频率控制
 * @Author zhangguoqiao
 * @Date 2022/12/13 02:16
 * @Version 1.0
 */
//@Component
public class DahuaDataTask {
    public static boolean getDataEnable = false;

    @Resource
    private SCADADemoHD scadaDemoHD;

//     @Scheduled(cron = "0 0 * * * *")
    private void changeState() {
        if (!getDataEnable) {
            getDataEnable = true;
            try {
                // 放开时间，ms
                Thread.sleep(30000);
                getDataEnable = false;
                scadaDemoHD.saveEnvToDataBase();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

//     @Scheduled(cron = "0 50 * * * *")
    private void loginAgain() {
        try {
            scadaDemoHD.loginAgain();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
